# Clear the workspace
rm(list=ls(all=TRUE))

# Load necessary libraries
library(MASS)
library(foreign)
library(readxl)

# Read the data
data_figure_1 <- read_excel("YourFiles/data_figure_1.xlsx")

# Extract relevant columns
mean <- data_figure_1$marg
lower <- data_figure_1$low
upper <- data_figure_1$high
name <- data_figure_1$riots
obs <- data_figure_1$obs

# Create y-axis positions
y.axis <- c(length(mean):1)
adjust <- 0 # create object to adjust points and lines up and down to distinguish between models

# Set margins for plot
par(mar=c(4, 5, 4, 5)) # Increase margins for better spacing

# Plot the mean points
plot(mean, y.axis + adjust, type = "p", axes = FALSE, xlab = "", ylab = "", pch = 19, cex = .75, xlim = c(-12, 20), xaxs = "r", main = " ") 

# Add segments for confidence intervals
segments(lower, y.axis + adjust, upper, y.axis + adjust, lwd = 1.5)

# Add horizontal axis
axis(1, at = seq(-12, 20, by = 1), labels = seq(-12, 20, by = 1), tick = TRUE, cex.axis = 0.75, mgp = c(2, 0.7, 0))

# Add left vertical axis
axis(2, at = y.axis + adjust, labels = name, las = 1, tick = TRUE, mgp = c(2, 0.6, 0), cex.axis = 0.75)

# Add right vertical axis
axis(4, at = y.axis + adjust, labels = obs, las = 1, tick = TRUE, mgp = c(3, 0.6, 0), cex.axis = 0.75)

# Add axis labels
mtext("Marginal Effect of Riots", side = 1, line = 2.5, cex = 0.75) # Label for horizontal axis
mtext("Rioting Level", side = 2, line = 3, cex = 0.75) # Label for left vertical axis
mtext("Cumulative Number of Observations in Sub-Sample", side = 4, line = 3, cex = 0.75) # Label for right vertical axis

# Add a vertical line at x = 0
abline(v = 0, lty = 2)
